public class Lc_JD {
   public class ListNode {
      int val;
     ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public ListNode removeElements(ListNode head, int val) {
        if(head == null){
            return null;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while(fast != null){
            if(fast.val == val){
                slow.next = fast.next;
                fast = fast.next;
            }else {
                slow = fast;
                fast = fast.next;
            }
        }
        if(head.val == val) {
            head = head.next;
        }
        return head;
    }

    public static void main(String[] args) {

    }
}
